GBML manual / Strings

string_digits

A whole number written as text with at least count digits, filled with zeros in front: string_digits(7, 3) is "007" and string_digits(5, 2) is "05". Made for clocks and scores: string_join(string_digits(minutes, 2), string_join(":", string_digits(seconds, 2))) is "01:07".

Syntax

string_digits(n, count) -> string

Arguments

NameType
nint
countint

Returns

string

Description

A whole number written as text with at least count digits, filled with zeros in front. string_digits(7, 3) is "007" and string_digits(5, 2) is "05". Made for clocks and scores.

Example

var minutes = 1;
var seconds = 7;
var clock = string_join(string_digits(minutes, 2), string_join(":", string_digits(seconds, 2)));

clock is "01:07".

The small print

Cost

One pass over the digits.

On the GBA

n must be a whole number (an int): string_digits(x, 3) with a real x is refused when the project is checked, so round it first with int_floor or int_round. A number with more digits than count shows all of them, never cut: string_digits(1234, 2) is "1234". A negative number gets a minus in front that is not counted: string_digits(-7, 3) is "-007". A count below 1 reads as 1. If the text would not fit in a string it is cut off at the end. string_from_number writes a number with no padding.

See also: stringstring_pad_leftstring_joinint_floor